//
//  RecommendTableViewCell.m
//  Journey
//
//  Created by dllo on 16/5/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RecommendTableViewCell.h"
#import "SubjectCollectionViewCell.h"
#import "SubjectViewController.h"
@interface RecommendTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,strong)BaseCollectionView *myCollectionView;
@end


@implementation RecommendTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createSubviews];
    }
    return self;
}

-(void)createSubviews
{
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake((WIDTH - 25) / 2, 120);
    flowLayout.minimumInteritemSpacing = 20;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.myCollectionView = [[BaseCollectionView alloc]initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
 
    self.myCollectionView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFFFF,0x363636);
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    //取消回弹
    self.myCollectionView.bounces = NO;
    
    [self.myCollectionView registerClass:[SubjectCollectionViewCell class] forCellWithReuseIdentifier:@"subjectCell"];
    [self.contentView addSubview:self.myCollectionView];

}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.myCollectionView.frame = CGRectMake(10 * WIDTHC, 10 * WIDTHC, WIDTH - 20 , self.contentView.frame.size.height - 20);
}




//cell数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return self.dataArray.count - 1 ;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
  //  self.myCollectionView.contentOffset =CGPointMake(190 * WIDTHC, 0);

    SubjectCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"subjectCell" forIndexPath:indexPath];
    
  //  cell.backgroundColor = [UIColor greenColor];

    cell.subModel = self.dataArray[indexPath.row + 1];
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    self.subjectBlock(indexPath.row + 1);
    
}




-(void)setTempArray:(NSMutableArray *)tempArray{
    _tempArray = tempArray;
    
    self.dataArray = [NSMutableArray arrayWithArray:_tempArray];
   // NSLog(@"==%@",self.dataArray);
    [self.myCollectionView reloadData];
}


@end
